<template>
  <div class="not-found">
    <div class="error-content">
      <div class="error-code">404</div>
      <img src="https://img1.baidu.com/it/u=2662682505,1738248369&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500" alt="404">
      <h2>页面不存在</h2>
      <p>您访问的页面可能已被删除、移动或暂时不可用</p>

      <div class="error-actions">
        <router-link to="/" class="back-btn primary">返回首页</router-link>
        <button @click="goBack" class="back-btn secondary">返回上一页</button>
      </div>

      <div class="countdown" v-if="countdown > 0">
        {{ countdown }} 秒后自动跳转到首页
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'NotFound',
  data () {
    return {
      countdown: 5,
      timer: null
    }
  },
  mounted () {
    this.startCountdown()
  },
  beforeDestroy () {
    if (this.timer) {
      clearInterval(this.timer)
    }
  },
  methods: {
    startCountdown () {
      this.timer = setInterval(() => {
        this.countdown--
        if (this.countdown <= 0) {
          clearInterval(this.timer)
          this.$router.push('/')
        }
      }, 1000)
    },
    goBack () {
      if (window.history.length > 1) {
        this.$router.go(-1)
      } else {
        this.$router.push('/')
      }
    }
  }
}
</script>

<style scoped>
.not-found {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  text-align: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}

.error-content {
  background: white;
  padding: 60px 40px;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
  max-width: 500px;
  width: 100%;
}

.error-code {
  font-size: 120px;
  font-weight: bold;
  color: #667eea;
  margin-bottom: 20px;
  line-height: 1;
}

img {
  width: 150px;
  height: 150px;
  margin-bottom: 30px;
  opacity: 0.8;
}

h2 {
  color: #333;
  margin-bottom: 15px;
  font-size: 28px;
}

p {
  color: #666;
  margin-bottom: 30px;
  font-size: 16px;
}

.error-actions {
  display: flex;
  gap: 15px;
  justify-content: center;
  margin-bottom: 20px;
}

.back-btn {
  padding: 12px 30px;
  font-size: 16px;
  text-decoration: none;
  border-radius: 25px;
  transition: all 0.3s ease;
  border: none;
  cursor: pointer;
  font-weight: 500;
}

.back-btn.primary {
  background-color: #667eea;
  color: white;
}

.back-btn.primary:hover {
  background-color: #5a6fd8;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.back-btn.secondary {
  background-color: transparent;
  color: #667eea;
  border: 2px solid #667eea;
}

.back-btn.secondary:hover {
  background-color: #667eea;
  color: white;
  transform: translateY(-2px);
}

.countdown {
  color: #999;
  font-size: 14px;
  margin-top: 20px;
}

@media screen and (max-width: 480px) {
  .error-content {
    padding: 40px 20px;
    margin: 20px;
  }

  .error-code {
    font-size: 80px;
  }

  .error-actions {
    flex-direction: column;
    align-items: center;
  }

  .back-btn {
    width: 200px;
  }
}
</style>
